/* ************************************************************************ */
/*                                                                          */
/*  haXe Video                                                              */
/*  Copyright (c)2007 Russell Weir                                          */
/*                                                                          */
/* This library is free software; you can redistribute it and/or            */
/* modify it under the terms of the GNU Lesser General Public               */
/* License as published by the Free Software Foundation; either             */
/* version 2.1 of the License, or (at your option) any later version.       */
/*                                                                          */
/* This library is distributed in the hope that it will be useful,          */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of           */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU        */
/* Lesser General Public License or the LICENSE file for more details.      */
/*                                                                          */
/* ************************************************************************ */
package so;
import hxmedia.Client;
import format.So;

class SharedObjectListener {
	var client(default,null) : Client;
	public var msgQueue(default,null) : SharedObjectMessage;

	public function new(client) {
		this.client = client;
		msgQueue = new SharedObjectMessage(null,0,false);
	}

	public function sendError(msg) {
		msgQueue.addCommand(CStatus,"error",msg);
	}

	public function addCommand(cmd : SoCommand, key : String, value) {
		msgQueue.addCommand(cmd,key,value);
	}

	public function broadcast() {
		if(msgQueue.length > 0) {
			client.writeSoMsg(msgQueue);
			msgQueue.clear();
		}
	}
}